package com.codermn.demo7;

/**
 * @author jxau_scf
 * @date 2021/6/20 - 17:10
 */
public class ChiHuo extends Thread {
    private BaoZi baoZi;
    public ChiHuo(BaoZi baoZi){
        this.baoZi = baoZi;
    }

    @Override
    public void run() {
        while (true){
            synchronized (baoZi){
                if (baoZi.isFlag() == false){
                    try {
                        baoZi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    System.out.println("吃货正在吃"+baoZi.getPi()+baoZi.getXian()+"的包子");
                    baoZi.setFlag(false);
                    baoZi.notify();
                    System.out.println("吃货已经把包子"+baoZi.getPi()+baoZi.getXian()+"的包子吃完了，请包子铺生产包子");
                }
            }
        }
    }
}
